import axios from "axios"
const state={
    shopListById:[],
    shopTypeList: [],
    allShopTypeList:[],
    shopList:[],


}
const mutations={
    CHANGE_SHOP_LIST_BY_ID(state,shopListById){
        state.shopListById=shopListById
    },
    CHANGE_SHOP_LIST(state,shopTypeList){
        state.shopTypeList=shopTypeList
    },
    CHANGE_ALL_SHOP(state,allShopTyeList){
        state.allShopTypeList=allShopTyeList

    },
    CHANGE_LIST(state,shopList){
        state.shopList=shopList
    },

}
const actions={
    getShopListById({commit},shopTypeId){
        axios.get("/shopList/"+shopTypeId)
            .then(data=>{
                commit("CHANGE_SHOP_LIST_BY_ID",data.shopList)
            })
    },
    getShopList({commit},params){
      axios.get("/shopList",{
          params
      }).then(data=>{
          commit("CHANGE_LIST",data.shopList)
      })
    },

   getShopTypeList({commit,dispatch},params){
       axios.get("/shopTypeList",{
           params
       }).then(data=>{
           commit("CHANGE_SHOP_LIST",data.shopTypeList)
       })
   },

    allShopTypeList({commit}){
        axios.get("/allShopTypeList")
            .then(data=>{
                commit("CHANGE_ALL_SHOP",data.shopTypeList)
            })
    },

    deleteShop({dispatch},id){
        axios.delete("/shopTypeList/"+id,{
            params:{
                id
            }
        })
            .then(data=>{
                if(data.ok===1)dispatch("getShopTypeList")
            })

    },
    deleteList({dispatch},id){
        axios.delete("/shopList/"+id,{
            params:{
                id
            }
        })
            .then(data=>{
                if(data.ok===1)dispatch("getShopList")
            })
    }
}
export default {
    state,
    mutations,
    actions
}